package org.farng.mp3.id3;

import org.farng.mp3.InvalidTagException;
import org.farng.mp3.object.ObjectByteArraySizeTerminated;
import org.farng.mp3.object.ObjectNumberFixedLength;

import java.io.IOException;


/**
 * Title: Description: Copyright:    Copyright (c) 2002 Company:
 *
 * @author Eric Farng
 * @version $Revision: 1.3 $
 */
public class FrameBodySIGN extends AbstractID3v2FrameBody {
    /**
     * Creates a new FrameBodySIGN object.
     */
    public FrameBodySIGN() {
        //        this.setObject("Group Symbol", new Byte((byte) 0));
        //        this.setObject("Signature", new byte[0]);
    }

    public FrameBodySIGN(FrameBodySIGN body) {
        super(body);
    }

    /**
     * Creates a new FrameBodySIGN object.
     *
     * @param groupSymbol DOCUMENT ME!
     * @param signature DOCUMENT ME!
     */
    public FrameBodySIGN(byte groupSymbol, byte[] signature) {
        this.setObject("Group Symbol", new Byte(groupSymbol));
        this.setObject("Signature", signature);
    }

    /**
     * Creates a new FrameBodySIGN object.
     *
     * @param file DOCUMENT ME!
     *
     * @throws IOException DOCUMENT ME!
     * @throws InvalidTagException DOCUMENT ME!
     */
    public FrameBodySIGN(java.io.RandomAccessFile file)
                  throws IOException, InvalidTagException {
        this.read(file);
    }

    /**
     * DOCUMENT ME!
     *
     * @param groupSymbol DOCUMENT ME!
     */
    public void setGroupSymbol(byte groupSymbol) {
        setObject("Group Symbol", new Byte(groupSymbol));
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public byte getGroupSymbol() {
        if (getObject("Group Symbol") != null) {
            return ((Byte) getObject("Group Symbol")).byteValue();
        } else {
            return 0;
        }
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public String getIdentifier() {
        return "SIGN" + ((char) 0) + getGroupSymbol() + ((char) 0) + (new String(getSignature()));
    }

    /**
     * DOCUMENT ME!
     *
     * @param signature DOCUMENT ME!
     */
    public void setSignature(byte[] signature) {
        setObject("Signature", signature);
    }

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public byte[] getSignature() {
        return (byte[]) getObject("Signature");
    }

    /**
     * DOCUMENT ME!
     */
    protected void setupObjectList() {
        objectList.add(new ObjectNumberFixedLength("Group Symbol", 1));
        objectList.add(new ObjectByteArraySizeTerminated("Signature"));
    }
}